#!/bin/bash
# 
# File: kill-autossh-self.sh
# Purpose: 根据条件查询autossh自己的进程
#

cd $(dirname "$0")
. ./common.sh

PORT=$1
exitcode=1
INSTALLDIR=$(cd "$(dirname "$0")"; pwd);

if [ -z "$PORT" ] ; then
    warn 'kill 所有的autossh进程';
	pids=`ps -ef |grep -w 'autossh'|grep 'NL'|awk '{print $2}'`;
    for pid in $pids; do
        kill -9 $pid && exitcode=0 && result 'kill进程'${pid}'成功';
    done
    exitcode=1;
else
	pids=`ps -ef |grep -w 'autossh'|grep ${PORT}:|awk '{print $2}'`;
	for pid in $pids; do
		kill -9 $pid && exitcode=0 && result 'kill进程'${pid}'成功';
	done
fi

exit $exitcode

# eof


